@extends('admin.common.main')

@section('cnt')
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span> 节点中心
        <span class="c-gray en">&gt;</span> 节点创建
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>

    <article class="page-container">

        @include('admin.common.msg')
        @include('admin.common.validate')

        <form action="{{ route('admin.node.store') }}" class="form form-horizontal" @submit.prevent="dopost">

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">是否顶级：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width:150px;">
                        <select class="select" @change="pidchange" size="1">
                            <option value="0">顶级</option>
                            @foreach($data as $node)
                                <option value="{{ $node['id'] }}">{{ $node['html'] }}{{ $node['name'] }}</option>
                            @endforeach
                        </select>
                    </span>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">
                    <span class="c-red">*</span>节点名称：
                </label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" name="name" v-model.lazy="info.name">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">路由别名：
                </label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" name="route_name" v-model.lazy="info.route_name">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">
                    <span class="c-red">*</span>是否主菜单：
                </label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input v-model.lazy="info.is_menu" type="radio" value="0" checked>
                        <label for="sex-1">否</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" value="1" v-model.lazy="info.is_menu">
                        <label for="sex-2">是</label>
                    </div>
                </div>
            </div>

            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="添加节点">
                </div>
            </div>
        </form>
    </article>
@endsection

@section('js')
    <script src="/js/vue.js"></script>
    {{--// 引入验证的jquery--}}
    <script>
        new Vue({
            el: '.page-container',
            // 数据
            data: {
                info: {
                    _token: '{{ csrf_token() }}',
                    name: '',
                    route_name: '',
                    is_menu: 0,
                    pid: 0,
                }
            },
            methods: {
                async dopost(evt) {
                    let url = evt.target.action;
                    let data = this.info;

                        {{--$.post(url, data).then(({msg, status}) => {--}}
                        {{--    if (status == 200) {--}}
                        {{--        layer.msg(msg, {icon: 1, time: 900});--}}
                        {{--        location.href = '{{ route('admin.node.index') }}';--}}
                        {{--    } else {--}}
                        {{--        layer.msg(msg, {icon: 2, time: 900});--}}
                        {{--    }--}}
                        {{--})--}}

                    let {msg, status} = await $.post(url, data);
                    if (status == 200) {
                        layer.msg(msg, {icon: 1, time: 900});
                        location.href = '{{ route('admin.node.index') }}';
                    } else {
                        layer.msg(msg, {icon: 2, time: 900});
                    }
                },
                // pid改变获取pid
                pidchange(evt) {
                    console.log(evt.target.value);
                    this.info.pid = evt.target.value || 0;
                    console.log(this.info.pid);
                }
            },
            // 生命周期
        })
    </script>
@endsection
